package com.pu.controller.user;

import com.pu.constant.StatusConstant;
import com.pu.entity.Category;
import com.pu.result.Result;
import com.pu.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Yusc
 * @Date 2023/10/31 16:49
 * @Version
 * @Description C端分类展示
 **/
@RestController("userCategoryController")
@RequestMapping("/user/category")
@Api(tags = "C端-分类接口")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * @param type
     * @return
     * @auther: Yusc
     * @date 2023/10/31 16:50
     * @Description 查询分类
     */
    @GetMapping("/list")
    @ApiOperation("查询分类")
    public Result<List<Category>> list(Integer type) {
        log.info("查询分类tpye: {}", type);
        List<Category> list = categoryService.lambdaQuery()
                .eq(type != null, Category::getType, type)    // 构造查询条件
                .eq(Category::getStatus, StatusConstant.ENABLE)
                .orderByAsc(Category::getSort)
                .list();
        return Result.success(list);
    }
}
